package com.leyou.upload.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSClientBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 创建OSS客户端
 */
@Configuration
public class OSSConfig {

    @Bean
    public OSS createOSSClient(OSSProperties prop){
        // 已经过时了
        // return new OSSClient(prop.getEndpoint(), prop.getAccessKeyId(), prop.getAccessKeySecret());

        // 现在我们使用新的方式去创建客户端
        return new OSSClientBuilder()
                .build(prop.getEndpoint(), prop.getAccessKeyId(), prop.getAccessKeySecret());
    }
}
